package hexapawn.game;

/**
 * class Cell - The object that represents an individual cell space in a hexapawn board.
 * 				Each cell contains a row and column location and a Piece object. If the
 * 				Piece object is null, then this cell is empty.
 * 
 * @author ChaoSXDemon
 *
 */
public class Cell {
	
	private int r, c;
	private Piece piece;	
	
	/**
	 * Constructor - Creates the Cell object at row = _r and column = _c
	 * 
	 * @param _r - The row to create the cell at
	 * @param _c - The column to create the cell at
	 */
	public Cell(int _r, int _c){
		r = _r;
		c = _c;
		piece = null;
	}
	
	/**
	 * Sets the piece of this cell
	 * 
	 * @param p - The piece to set to
	 */
	public void setPiece(Piece p){
		piece = p;
		piece.moveTo(r, c);
	}
	
	/**
	 * Removes the Piece object in this cell. If this cell is empty, nothing
	 * is changed.
	 * 
	 */
	public void removePiece(){
		piece = null;
	}
	
	/**
	 * See if this cell has a piece object.
	 * 
	 * @return - true if piece is not null, false otherwise
	 */
	public boolean hasPiece(){
		return piece != null;
	}
	
	/**
	 * Returns the row location of this cell.
	 * 
	 * @return - the row location
	 */
	public int getRow(){
		return r;
	}
	
	/**
	 * Returns the column location of this cell
	 * 
	 * @return - the column
	 */
	public int getColumn(){
		return c;
	}
	
	/**
	 * Returns the piece on this cell
	 * 
	 * @return - null if this cell is empty else returns the actual
	 * 			 Piece object
	 */
	public Piece getPiece(){
		return piece;
	}
	
	/**
	 * Returns the String of this Cell
	 * 
	 * @return - The String representation of Cell object
	 */
	public String toString(){
		String str = "Cell - ("+r+","+c+")";
		return str;
	}
	
	/**
	 * Returns true if this Cell has the same row and column location as
	 * the input parameter other.
	 * 
	 * @param other - The other Cell object to compare to
	 * @return - True if they have the same location false otherwise
	 */
	public boolean equals(Cell other){
		return ((other.r == r) && (other.c == c));
	}

}
